// 11-散列2 Hashing

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MaxSize 100000

typedef struct {
    int capacity;
    int data[MaxSize];
} HashTable;

// 计算不小于 N 的最小素数
int nextPrime(int n) {
    if(n <= 2)
		return 2;
	if (n == 3)
		return n;
    int prime = n % 2 == 0 ? n + 1 : n;
    while (1) {
        int flag = 1;
        for (int i = 2; i * i <= prime; i++) {
            if (prime % i == 0) {
                flag = 0;
                break;
            }
        }
        if (flag) break;
        prime += 2;
    }
    return prime;
}

HashTable* createHashTable(int capacity) {
    HashTable* h = (HashTable*) malloc(sizeof(HashTable));
    h->capacity = nextPrime(capacity);
    for (int i=0; i<h->capacity; i++) {
        h->data[i] = -1;
    }
    return h;
}

int insert(HashTable* h, int value) {
    int index = value % h->capacity;
    int times = 0;
    while (times < 2*h->capacity && h->data[index] != -1 && h->data[index] != value) {
        times++;
        index = (value + times * times) % h->capacity;
    }
    if (times < 2*h->capacity) {
        h->data[index] = value;
        return index;
    }
    return -1;
}

void printIndex(int index) {
    if (index == -1) {
        printf("-");
    } else {
        printf("%d", index);
    }
}

int main() {
    int m, n;
    scanf("%d%d", &m, &n);
    // create hash table
    HashTable *h = createHashTable(m);
    // input value
    for (int i=0; i<n; i++) {
        int value;
        scanf("%d", &value);
        if (i != 0) {
            printf(" ");
        }
        int index = insert(h, value);
        printIndex(index);
    }
    printf("\n");
    free(h);
    return 0;
}
